﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using System.Xml;
using Styx;
using Styx.Common;
using Styx.CommonBot;
using Styx.CommonBot.Inventory;
using Styx.Pathing;
using Styx.TreeSharp;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;

namespace KingWoW
{
    class HealInterruptDispellsCleanse_Manager
    {
        private bool ReadNextXMLData;
        private XmlTextReader XmlReader;

        public HealInterruptDispellsCleanse_Manager()
        {
            LoadDontHealList();
        }

        #region HEAL
        private string DontHealListPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                                   string.Format(
                                                       @"Routines/king-wow/XML/DontHealList.xml"));
        private string DontHealListString;

        private void LoadDontHealList()
        {
            //Get ListHealDoNot to String
            DontHealListString = "";
            XmlReader = new XmlTextReader(DontHealListPath);
            while (XmlReader.Read())
            {
                if (XmlReader.NodeType == XmlNodeType.Element && XmlReader.Name == "SID")
                {
                    ReadNextXMLData = true;
                }
                if (XmlReader.NodeType == XmlNodeType.Text && ReadNextXMLData)
                {
                    DontHealListString = DontHealListString + "[" + XmlReader.Value + "] ";
                    ReadNextXMLData = false;
                }
            }
            XmlReader.Close();
        }

        public bool TargetDontHeal(WoWUnit target)
        {
            using (StyxWoW.Memory.AcquireFrame())
            {
                if (target == null || !target.IsValid || !target.IsAlive)
                    return false;

                bool dontheal = target.Debuffs.Values.Any(a => DontHealListString.Contains("[" + a.SpellId + "]"));

                return dontheal;
            }
        }
        #endregion

    }
}
